package com.service.impl;

import com.entity.LoginRecord;
import com.entity.MaterialInput;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mapper.LoginRecordMapper;
import com.service.LoginRecordService;
import com.utils.PageObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LoginRecordServiceImpl implements LoginRecordService {

    @Autowired
    private LoginRecordMapper loginRecordMapper;

    //保存登录记录
    @Override
    public boolean save(LoginRecord loginRecord) {
        return loginRecordMapper.insert(loginRecord);
    }

    @Override
    public PageObject<LoginRecord> loginRecordList(PageObject pageObject) {
        //开始分页
        PageHelper.startPage(pageObject.getCurrent(),pageObject.getSize());
        //查询数据
        List<LoginRecord> list = loginRecordMapper.list();
        //PageHelper包装数据
        PageInfo<LoginRecord> pageInfo = new PageInfo<>(list);
        //将数据封装进PageResult
        PageObject<LoginRecord> userPageResult
                = new PageObject<>(pageInfo.getPageNum(), pageInfo.getPageSize(), pageInfo.getTotal(), pageInfo.getList());
        return userPageResult;
    }
}
